package com.easy.project.controller.builder;

import com.easy.project.base.result.BizResult;
import com.easy.project.domain.dto.builder.BuilderDTO;
import com.easy.project.domain.dto.builder.DataSourceDTO;
import com.easy.project.domain.vo.builder.SelectTableVO;
import com.easy.project.service.builder.IBuilderCodeService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 代码生成器
 * @author wxz
 */
@RestController
@RequestMapping("/builder")
@Api(tags = "后端代码创建接口")
public class BuilderCodeController {

    @Resource
    private IBuilderCodeService builderCodeService;

    /**
     * 生成代码
     * @param builderDTO
     * @return
     */
    @PostMapping("/code")
    public BizResult<Void> builder(@Validated @RequestBody BuilderDTO builderDTO){
        builderCodeService.builder(builderDTO);
        return BizResult.success();
    }

    /**
     * 获取数据库连接的所有表名
     * @param dataSourceDTO
     * @return
     */
    @GetMapping("/table-names")
    public BizResult<List<SelectTableVO>> tableNames(DataSourceDTO dataSourceDTO){
        return BizResult.success(builderCodeService.tableNames(dataSourceDTO));
    }
}
